/*******************************************************************
 * Copyright (c) 2013 珠海比特讯科技有限公司. All rights reserved.
 * （1）软件的版权将受到法律保护，不允许非经授权的使用；
 * （2）未经版权所有人授权，任何人不得修改、复制和传播软件源代码、图片及其它资源等；
 * （3）未经版权所有人授权，不允许对软件进行修改；
 * （4）未经版权所有人授权，不允许在该软件的基础上开发新的软件；
 * （5）珠海比特讯科技有限公司拥有最终解释权
 *******************************************************************/
package youxiao.bytezon.views.courses;

import java.math.BigDecimal;
import java.util.Set;

import youxiao.bytezon.models.Course;
import youxiao.bytezon.models.CourseDetail;
import youxiao.bytezon.models.StudentCourse;
import youxiao.bytezon.utils.BeanUtil;
import youxiao.bytezon.views.course_details.CourseDetailView;
import youxiao.bytezon.views.coursetypes.CoursetypeView;
import youxiao.bytezon.views.students.StudentView;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonInclude.Include;
import com.google.common.base.Function;
import com.google.common.collect.FluentIterable;

public class CourseView {

	private long id;
	private String name;
	private BigDecimal price;
	private int applylearnCount;
	private int trialCount;
	private int lessonCount;
	private int finishLessonCount;
	private String courseTime;
	private String schoolName;
	private CoursetypeView coursetype;
	@JsonInclude(Include.NON_NULL)
	private Set<CourseDetailView> courseDetails;
	@JsonInclude(Include.NON_NULL)
	private Set<StudentView> students;

	public CourseView(Course course) 	{	
		BeanUtil.copyTableProps(course, this);

		this.name = course.getShortName() + course.getExtName();
		this.schoolName = course.getSchool().getName();
		this.coursetype = new CoursetypeView();
		BeanUtil.copyTableProps(course.getCoursetype(), this.coursetype, "id");
	}

	public CourseView(Course course, boolean isShowCourseDetails) {
		this(course);

		if (isShowCourseDetails) {
			this.courseDetails = FluentIterable.from(course.getCourseDetails()).transform(new Function<CourseDetail, CourseDetailView>() {
				public CourseDetailView apply(CourseDetail courseDetail) {
					return new CourseDetailView(courseDetail);
				}
			}).toSet();

			this.students = FluentIterable.from(course.getStudentCourses()).transform(new Function<StudentCourse, StudentView>() {
				public StudentView apply(StudentCourse studentCourse) {
					StudentView student = new StudentView(studentCourse.getStudent());
					student.setIsTrial(studentCourse.isTrial());
					return student;
				}
			}).toSet();
		}
	}

	public long getId() {
		return id;
	}

	public void setId(long id) {
		this.id = id;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public BigDecimal getPrice() {
		return price;
	}

	public void setPrice(BigDecimal price) {
		this.price = price;
	}

	public int getLessonCount() {
		return lessonCount;
	}

	public void setLessonCount(int lessonCount) {
		this.lessonCount = lessonCount;
	}

	public int getFinishLessonCount() {
		return finishLessonCount;
	}

	public void setFinishLessonCount(int finishLessonCount) {
		this.finishLessonCount = finishLessonCount;
	}

	public String getCourseTime() {
		return courseTime;
	}

	public void setCourseTime(String courseTime) {
		this.courseTime = courseTime;
	}

	public String getSchoolName() {
		return schoolName;
	}

	public void setSchoolName(String schoolName) {
		this.schoolName = schoolName;
	}

	public CoursetypeView getCoursetype() {
		return coursetype;
	}

	public void setCoursetype(CoursetypeView coursetype) {
		this.coursetype = coursetype;
	}

	public int getApplylearnCount() {
		return applylearnCount;
	}

	public void setApplylearnCount(int applylearnCount) {
		this.applylearnCount = applylearnCount;
	}

	public int getTrialCount() {
		return trialCount;
	}

	public void setTrialCount(int trialCount) {
		this.trialCount = trialCount;
	}

	public Set<CourseDetailView> getCourseDetails() {
		return courseDetails;
	}

	public void setCourseDetails(Set<CourseDetailView> courseDetails) {
		this.courseDetails = courseDetails;
	}

	public Set<StudentView> getStudents() {
		return students;
	}

	public void setStudents(Set<StudentView> students) {
		this.students = students;
	}

}
